package com.atguigu.ssyx.sys.controller;

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.sys.Region;
import com.atguigu.ssyx.sys.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-18 17:23 星期二
 * description:
 */
@Api(tags = "区域管理")
@RequestMapping("/admin/sys/region")
@RestController
@CrossOrigin  //跨域
public class RegionController {
    
    @Autowired
    private RegionService regionService;

    /**
     * 根据关键字查找地区
     * @return
     */
    @ApiOperation(value = "根据关键字查找地区")
    @GetMapping("/findRegionByKeyword/{keyword}")
    public Result findRegionByKeyword(@PathVariable("keyword") String keyword){
        List<Region> list = regionService.findRegionByKeyword(keyword);
        return Result.ok(list);
    }

    /**
     * 根据parent_id查找地区
     * @return
     */
    @ApiOperation(value = "根据parent_id查找地区")
    @GetMapping("/findByParentId/{parentId}")
    public Result findByParentId(@PathVariable("parentId") Long parentId){
        //一个上级地区下有多个子级地区
        List<Region> list = regionService.findByParentId(parentId);
        return Result.ok(list);
    }
}
